﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hive.Core;

namespace Hive.Bot.Tasks
{
    public class ClearHiveTask: MoveTask
    {
        public ClearHiveTask(): base(new Location(0, 0))
        {

        }
        public override IEnumerable<int> CalculateEfficiencies(IEnumerable<Ant> ants)
        {
            List<int> result = new List<int>();
            foreach (var a in ants)
            {
                if (Env.MyHills.Contains(a.Location))
                {
                    result.Add(1);
                }
                else
                {
                    result.Add(0);
                }
            }

            return result;
        }

        public override Order Execute()
        {
            foreach (var d in Engine.Aim.Values)
            {
                if (!Env.MyAnts.Any(a => a.Location == ant.Location + d) && Env.Map.GetIsPassable(ant.Location + d))
                {
                    return new Order()
                    {
                        Ant = ant,
                        Destination = ant.Location + d,
                        Efficiency = 0
                    };
                }
            }

            return new Order()
            {
                Ant = ant,
                Destination = ant.Location,
                Efficiency = 0
            };
        }
    }
}
